package com.risk;

import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

@Data
@ToString
public class ReturnT<T> implements Serializable {

    private Boolean isSuccess;

    private String code;

    private String message;

    private T data;

    private static String SUCCESS_CODE="0";

    private static String DEFAULT_FAIL_CODE="404";

    public ReturnT(Boolean isSuccess, String code, String message, T data) {
        this.isSuccess = isSuccess;
        this.code = code;
        this.message = message;
        this.data = data;

    }

    public static <T> ReturnT<T>  returnOK(T data){
       return new ReturnT<>(true,SUCCESS_CODE,"成功",data);
    }

    public static <T> ReturnT<T>  returnOK(T data,String message){
        return new ReturnT<>(true,SUCCESS_CODE,"成功",data);
    }

    public static <T> ReturnT<T>  returnFail(String code,String message){
        return new ReturnT<>(false,code,message,null);
    }

    public static <T> ReturnT<T>  returnFail(String message){
        return new ReturnT<>(false,DEFAULT_FAIL_CODE,message,null);
    }

}
